import React, { Component } from 'react';
import './Demo1.scss'
import { NavBar } from 'antd-mobile';
import TabBar from '../../components/TabBar';
import { bindActionCreators } from 'redux';
import { redirect, getData } from '../../redux/actions/global';
import { connect } from 'react-redux';
import fetch from '../../utils/fetch';
import API from '../../constants/api';

class Demo1 extends Component {
  state = {
    data: [{
      article_num: "579306",
      class_id: "6",
      custom:1,
      img_url: "/app/upload/user/1501126220_9175_thumb.png",
      name: "博闻博论",
      visit_num: "1523"
    }]
  }
  componentDidMount(){
    // console.log('process.env.NODE_ENV',process.env.NODE_ENV);
    // 模拟get
    // fetch(API.INDEX_FIND, 'get', {
    //   page: 1,
    //   size: 10
    // })
    // .then(data => {
    //   this.setState({
    //     data: data.data.items
    //   })
    // });

    getData('http://teacher.edu.cn/jiaoyu/item/index', 'get', {}).then((data)=>{
      console.log('data',data);
      this.setState({
        data: data.data
      })
    })


    // 模拟post
    // fetch('http://teacher.edu.cn/jiaoyu/item/index11', 'post', {
    //   page: 1,
    //   size: 10
    // })
    // .then(data => {
    //   console.log('data',data);
    //   this.setState({
    //     // data: data.data.items
    //   })
    // });
  }
  render() {
    const { redirect } = this.props;
    return (
      <div className="page">
        <NavBar>Demo1</NavBar>
        <TabBar />
        <div className="content demo1">
          <div>{this.state.data.map((data, index) => {
            return <div key={index}>{data.name}</div>
          })}</div>
          <div onClick={redirect.bind(this, '/demo5', 'left')}>列表</div>
          <div onClick={redirect.bind(this, '/demo6/name', 'left')}>传参数</div>
        </div>
      </div>
    );
  }
}


const mapStateToProps = (state) => {
  return {
  }
}
// redux 绑定dispath
const mapDispatchToProps = (dispatch) => {
  return {
    redirect: bindActionCreators(redirect, dispatch)
  }
}

Demo1 = connect(mapStateToProps, mapDispatchToProps)(Demo1)
export default Demo1;
